#include "infoview.h"
#include <QPainter>
#include "../external/transformable/transformable.h"

// 声明图层为全局变量
std::shared_ptr<InfoView> info_view = nullptr;

// 同步图层（绘制简单，更新率高）
InfoView::InfoView() {}

void InfoView::draw(QPixmap &pixmap)
{
    QPainter painter(&pixmap);
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.setRenderHint(QPainter::TextAntialiasing, true);

    // 绘制圆角框
    QRectF rect(10, 10, 260, 60);
    QColor orange(255, 165, 0, 180);
    painter.setPen(Qt::NoPen);
    painter.setBrush(orange);
    painter.drawRoundedRect(rect, 10, 10);

    // 设置文字属性
    painter.setPen(Qt::white);
    QFont font = painter.font();
    font.setBold(true);
    font.setPointSize(12);
    painter.setFont(font);

    // 获取光标位置
    double x, y, px, py;
    TRANS->cursorInPixel(px, py);
    TRANS->cursorInMap(x, y);

    // 获取窗口内瓦片数量

    QString info = QString("Pixel: (%1,%2)\nMap: (%3,%4)\nVisible Tiles: %5")
                       .arg(int(px), 7, 10, QChar(' '))
                       .arg(int(py), 7, 10, QChar(' '))
                       .arg(x, 7, 'f', 2, QChar(' '))
                       .arg(y, 7, 'f', 2, QChar(' '));

    painter.drawText(rect.adjusted(10, 10, -10, -10), Qt::AlignLeft | Qt::AlignTop, info);
}
